#!/bin/csh -xf

# This is a small script to produce gif and html files from a postscript
# schedule file. 
 
# From /www/observing/schedules go into the subdirectory
# with the .ps file (e.g. CA.ps) using the cd command.

# Then type e.g.:
# ../make_gifs_html CA "98SEPT"

# For Mopra schedules, replace the CA with Mopra and change the title.
# Do not forget the quotes around the title.

#########################################################
setenv PATH /usr/local/X11/bin:/usr/local/gnu/bin:${PATH}

#pstopnm -xborder 0.0 -yborder 0.0 -ysize 1000 $1.ps >& /dev/null
#../make_ppm -llx 0 -lly 0 -urx 7 -ury 10 -ysize 1111 $1.ps >& /dev/null
../make_ppm -llx 0 -lly 0 -urx 7 -ury 10 -ysize 1111 $1.ps 
#grep 'Schedule' $1.ps | sed -e 's#).*$#</A>#' -e 's#(#<LI><A HREF=xxxgif > #'\
# >! $1.dates
set title="$2";
if ($#title == 0) set title="Schedule"

if ( "$1" == "CA" ) then
  set udir = "atca"
  set idir = "ca"
else if ( "$1" == "SU" ) then
  set udir = "atca-subarray"
  set idir = "ca"
else
  set udir = "mopra"
  set idir = "mopra"
endif
set p1 = '<\!--#include virtual="/includefiles/'
set p2 = '.html" -->'


set j=0;
foreach i (/tmp/junk/$1*.ppm)
  @ j = $j + 1
  (pnmcrop $i > ${i}_crop ) >& /dev/null
  (pnmcut 270 24 160 20 ${i}_crop > ${i}_index )
  set gifname = $i:t
  set gifname = `echo $gifname | sed 's/ppm/gif/'`
  (ppmtogif -transparent white ${i}_index > ${gifname}_in )
  (ppmtogif -transparent white ${i}_crop > $gifname )
  'rm' $i ${i}_crop ${i}_index
end
rm -rf /tmp/junk


# Create HTML pages (one for each schedule-gif)
foreach k ($1*.gif)


set htmlname = `echo $k | sed 's/gif/html/'`
echo "<HTML>" > $htmlname
echo "<HEAD>" >> $htmlname
echo "<title> Schedule $2 </title>" >> $htmlname
echo "<link rel=stylesheet type=text/css href=/stylesheets/${idir}_style.css>" >> $htmlname
echo "</HEAD>" >> $htmlname
echo "<BODY>" >> $htmlname
echo "$p1${idir}_header$p2" >> $htmlname
echo "<TABLE cellspacing=10 border=0><tr>" >> $htmlname
echo "<td align=center valign=top>" >> $htmlname
echo "<h1 align=center>$2</h1>" >> $htmlname

foreach gifin ($1*.gif_in)
set htmlpage = `echo $gifin | sed 's/gif_in/html/'`
echo "<a href=$htmlpage><img src=$gifin border=1></A><p>" >> $htmlname
end

echo "<p><a href=${udir}-summary.html>Schedule Summary</A>" >> $htmlname
echo "<p><a href=/observing/schedules/>Back to Schedule Index</A>" >> $htmlname
echo "</td>" >> $htmlname

set size = (`/DATA/KAPUTAR_1/operations/bin/image_size.pl $k`)
echo "<td valign=top><img src=$k width=$size[1] height=$size[2]></td>" >> $htmlname
echo "</tr></TABLE>" >> $htmlname

echo "<p><hr><ADDRESS>" >> $htmlname
echo "Last Modified: " >> $htmlname
echo "Phil Edwards" >> $htmlname
date +"(%d-%b-%Y)" >> $htmlname
echo "</ADDRESS>" >> $htmlname
echo "$p1${idir}_footer$p2" >> $htmlname
echo "</BODY>" >> $htmlname
echo "</HTML>" >> $htmlname

chmod u+x $htmlname

end
